using UnityEngine;
public class PlayerHealth : EntityHealth
{
    private Player_Stat playerStat;

    protected override void Awake()
    {
        base.Awake();
        playerStat = GetComponent<Player_Stat>();
    }
    protected override void OnEnable()
    {
        base.OnEnable();
        currentHealth = playerStat.GetMaxHealth();
    }

    private void Start()
    {
        EventCenter.TriggerEvent(EventName.UI_UpdateHealthBar, currentHealth, playerStat.GetMaxHealth());
    }

    public void TriggerUpdateHealthBar()
    {
        EventCenter.TriggerEvent(EventName.UI_UpdateHealthBar, playerStat.GetMaxHealth(), playerStat.GetMaxHealth());
    }
    
    public override void TakeDamage(float damage, Vector2 hurtDir)
    {
        float finalDamage = damage / playerStat.GetArmorCoefficient();

        base.TakeDamage(finalDamage, hurtDir);
    }

    public override bool ReduceHealth(float damage, Vector2 hurtDir)
    {
        bool isHurt = base.ReduceHealth(damage, hurtDir);
        if (isHurt)
            EventCenter.TriggerEvent(EventName.PlayerHurt);

        EventCenter.TriggerEvent(EventName.UI_UpdateHealthBar, currentHealth, playerStat.GetMaxHealth());

        return isHurt;
    }
    public override void Dead(Vector2 hurtDir)
    {
        base.Dead(hurtDir);
        EventCenter.TriggerEvent(EventName.PlayerDead);
    }
}
